#ifndef __ALAMRS_H__
#define __ALAMRS_H__

#include "sys_def.h"

#define ACL_INACTIVE   0
#define ACL_PREACTIVE  1
#define ACL_ACTIVE     2
#define ACL_POSTACTIVE 3

#define ACL_ENABLE   0
#define ACL_SUPPRESS 1
#define ACL_DISABLE  2

// alarm acl def
enum {
    //温湿度报警
    ACL_HI_TEMP_RETURN = 0,
    ACL_LO_TEMP_RETURN,
    ACL_HI_HUM_RETURN,
    ACL_LO_HUM_RETURN,
    ACL_WATER_OVERFLOW,  //水浸
    ACL_SMOKE_ALARM,     //烟雾告警
    ACL_RESERVE_00,
    ACL_RESERVE_01,
    ACL_GATE_OPEN,     //门控打开
    ACL_MBM_COM_LOSS,  // modbus slave 通信错误
    ACL_NTC_INVALID,
    ACL_RESERVE_02,
    ACL_POWER_LOSS,  //断电重启
    ACL_RESERVE_04,
    ACL_RESERVE_05,
    ACL_RESERVE_06,
    ACL_PDU_HI_VOLTAGE,
    ACL_PDU_LO_VOLTAGE,
    ACL_PDU_HI_CURRENT,
    ACL_RESERVE_10,
    ACL_PDU_01_HI_VOLTAGE,
    ACL_PDU_01_LO_VOLTAGE,
    ACL_PDU_01_HI_CURRENT,
    ACL_RESERVE_14,
    ACL_PDU_02_HI_VOLTAGE,
    ACL_PDU_02_LO_VOLTAGE,
    ACL_PDU_02_HI_CURRENT,
    ACL_RESERVE_18,
    ACL_PDU_03_HI_VOLTAGE,
    ACL_PDU_03_LO_VOLTAGE,
    ACL_PDU_03_HI_CURRENT,
    ACL_RESERVE_1C,
    ACL_IPM_HI_FD,  // freqency deviation
    ACL_IPM_LO_FD,
    ACL_IPM_A_HIGH,
    ACL_IPM_B_HIGH,
    ACL_IPM_C_HIGH,
    ACL_IPM_A_LOW,
    ACL_IPM_B_LOW,
    ACL_IPM_C_LOW,
    ACL_RESERVE_20,
    ACL_RESERVE_21,
    ACL_RESERVE_22,
    ACL_RESERVE_23,
    ACL_RESERVE_24,
    ACL_RESERVE_25,
    ACL_RESERVE_26,
    ACL_RESERVE_27,
    ACL_UPS_ERR,       // UPS故障
    ACL_UPS_AC_POWER,  //市电异常
    ACL_RESERVE_32,
    ACL_RESERVE_33,
    ACL_RESERVE_34,
    ACL_RESERVE_35,
    ACL_RESERVE_36,
    ACL_RESERVE_37,
    ACL_RESERVE_38,
    ACL_RESERVE_39,
    ACL_RESERVE_3A,
    ACL_RESERVE_3B,
    ACL_RESERVE_3C,
    ACL_RESERVE_3D,
    ACL_RESERVE_3E,
    ACL_RESERVE_3F,
    ACL_RESERVE_40,
    ACL_RESERVE_41,
    ACL_RESERVE_42,
    ACL_RESERVE_43,
    ACL_RESERVE_44,
    ACL_RESERVE_45,
    ACL_RESERVE_46,
    ACL_RESERVE_47,
    ACL_RESERVE_48,
    ACL_RESERVE_49,
    ACL_RESERVE_4A,
    ACL_RESERVE_4B,
    ACL_RESERVE_4C,
    ACL_RESERVE_4D,
    ACL_RESERVE_4E,
    ACL_RESERVE_4F,
    ACL_SENSOR1_COM,
    ACL_SENSOR2_COM,
    ACL_SENSOR3_COM,
    ACL_SENSOR4_COM,
    ACL_SENSOR5_COM,
    ACL_SENSOR6_COM,
    ACL_SENSOR7_COM,
    ACL_SENSOR8_COM,
    ACL_RESERVE_58,
    ACL_RESERVE_59,
    ACL_RESERVE_5A,
    ACL_UPS1_COM,
    ACL_UPS2_COM,
    ACL_DTU_COM,
    ACL_RESERVE_5E,
    ACL_RESERVE_5F,
    //保留
    ACL_AC_OVERFLOW,          // ID96（严重）空调溢水告警
    ACL_AC_SUCTIONTEMP,       // ID97（严重）空调吸气温度故障告警
    ACL_AC_SUCTIONPRE,        // ID98（严重）空调吸气压力故障告警
    ACL_AC_RETURN_TEMP,       // ID99（严重）空调回风温度故障告警
    ACL_AC_RETURN_HUM,        // ID100（严重）空调回风湿度故障告警
    ACL_AC_SUPPLY_TEMP,       // ID101（严重）空调送风温度故障告警
    ACL_AC_EXHAUST_PRE,       // ID102（严重）空调排气压力故障告警
    ACL_AC_EXHAUST_TEMP,      // ID103（严重）空调排气温度故障告警
    ACL_AC_HIGH_TEMP,         // ID104（严重）空调高温告警
    ACL_AC_LOW_TEMP,          // ID105（严重）空调低温告警
    ACL_AC_HIGH_HUM,          // ID106（严重）空调高湿告警
    ACL_AC_LOW_HUM,           // ID107（严重）空调低湿告警
    ACL_AC_HIGH_PRE,          // ID108（严重）空调高压告警
    ACL_AC_LOW_PRE,           // ID109（严重）空调低压告警
    ACL_AC_EXHAUST,           // ID110（严重）空调排气告警
    ACL_AC_HIGHPRE_LOCK,      // ID111（严重）空调高压锁定告警
    ACL_AC_LOWPRE_LOCK,       // ID112（严重）空调低压锁定告警
    ACL_AC_EXHAUST_LOCK,      // ID113（严重）空调排气锁定告警
    ACL_AC_SUCTION_LOWTEMP,   // ID114（严重）空调吸气低温告警
    ACL_AC_SUCTION_HIGHTEMP,  // ID115（严重）空调吸气高温告警
    ACL_AC_COMDRV_COMERR,     // ID116（严重）空调压缩机变频器通讯故障
    ACL_AC_DRV_01,            // ID117（严重）空调压缩机变频器过流保护
    ACL_AC_DRV_02,            // ID118（严重）空调压缩机变频器过压保护
    ACL_AC_DRV_03,            // ID119（严重）空调压缩机变频器欠压保护
    ACL_AC_DRV_04,            // ID120（严重）空调压缩机过载保护
    ACL_AC_DRV_05,            // ID121（严重）空调压缩机变频器过载保护
    ACL_AC_DRV_06,            // ID122（严重）空调压缩机变频器功率模块保护
    ACL_AC_DRV_07,            // ID123（严重）空调压缩机变频器外设保护
    ACL_AC_DRV_08,            // ID124（严重）空调压缩机变频器通讯保护
    ACL_AC_DRV_09,            // ID125（严重）空调压缩机变频器EEPROM保护
    ACL_AC_DRV_10,            // ID126（严重）空调压缩机变频器失步保护
    ACL_AC_DRV_11,            // ID127（严重）空调压缩机变频器故障
    ACL_AC_DRV_12,            // ID128（严重）空调压缩机变频器锁定
    ACL_RESERVE_81,
    //异常
    ACL_TOTAL_NUM,

};

// Alair,20161227
enum {
    DEV_RETURN_SENSOR1_FAULT_BPOS = 0,
    DEV_RETURN_SENSOR2_FAULT_BPOS,
    DEV_RETURN_SENSOR3_FAULT_BPOS,
    DEV_RETURN_SENSOR4_FAULT_BPOS,
    DEV_SUPPLY_SENSOR1_FAULT_BPOS,
    DEV_SUPPLY_SENSOR2_FAULT_BPOS,
    //
    DEV_TEM_HUM_RESERVE1_FAULT_BPOS,
    DEV_TEM_HUM_RESERVE2_FAULT_BPOS,
    //
    DEV_NTC7_BPOS,
    DEV_NTC8_BPOS,
    DEV_CIOL_NTC1_FAULT_BPOS,
    DEV_CIOL_NTC2_FAULT_BPOS,
    DEV_RETUREN_NTC1_FAULT_BPOS,
    DEV_RETUREN_NTC2_FAULT_BPOS,
    DEV_SUPPLY_NTC1_FAULT_BPOS,
    DEV_SUPPLY_NTC2_FAULT_BPOS,
};

//短信告警
typedef struct {
    uint8_t Alarm_ACL;   //告警号
    uint8_t Alarm_Flag;  //告警标识
    uint8_t Alarm_Addr;  //告警地址
} In_Alarm_st;

void alarm_acl_init(void);
void alarm_acl_exe(void);

uint8_t get_alarm_bitmap(uint8_t alarm_id);

uint8_t clear_alarm(uint8_t alarm_id);
uint8_t get_alarm_bitmap_mask(uint8_t component_bpos);
uint8_t get_alarm_bitmap_op(uint8_t component_bpos);

#endif  //__ALAMRS_H__
